﻿<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>书籍列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/default/easyui.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/manager/easyui/themes/icon.css}">
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/manager/easyui/jquery.easyui.min.js}"></script>
	<script type="text/javascript">
	    //工具栏
	    var toolbar = [{
	        text: '修改',
	        iconCls: 'icon-edit',
	        handler: function () {
                var row=$('#booklist').datagrid('getSelected');
                            $('#dd').dialog("open");
                $.ajax({
                    url:"/manager/book/findbook",
                    type: "post",
                    dataType: "json",
                    data:{
                      id:row.id
                    },
                    success: function(result){
                        if(result.success){
                            $("#bookname").textbox('setValue',result.obj.bookname);
                            $("#price").textbox('setValue',result.obj.price);
                            $("#groupprice").textbox('setValue',result.obj.groupprice);
                            $("#bookintroduce").textbox('setValue',result.obj.bookintroduce);
                            $("#authorintroduce").textbox('setValue',result.obj.authorintroduce);
                        }else{
                            alert(result.msg);
                        }
                    },
                    error:function(){
                        alert('系统异常');
                    }
                })


            }
	    }, '-', {
	        text: '启用',
	        iconCls: 'icon-ok',
	        handler: function () {
	            var row=$('#booklist').datagrid('getSelected');


	            $.ajax({
                    url:"/manager/book/enable",
                    type:"post",
                    dataType:"json",
                    data:{
                        id:row.id
                    },
                    success:function (result) {
                        if(result.success){
                            alert("修改成功");
                            $('#booklist').datagrid('reload');
                        }else {
                            alert(result.msg);
                            $('#booklist').datagrid('reload');
                        }
                    },
                    error:function () {
                        alert("数据异常");
                    }
                })
            }
	    }, '-', {
	        text: '禁用',
	        iconCls: 'icon-cancel',
	        handler: function () {
                var row=$('#booklist').datagrid('getSelected');
                $.ajax({
                    url:"/manager/book/disable",
                    type:"post",
                    dataType:"json",
                    data:{
                        id:row.id
                    },
                    success:function (result) {
                        if(result.success){
                            alert("修改成功");
                            $('#booklist').datagrid('reload');
                        }else {
                            alert(result.msg);
                            $('#booklist').datagrid('reload');
                        }
                    },
                    error:function () {
                        alert("数据异常");
                    }
                })
            }
	    }];
	   $(function(){
	       $('#booklist').datagrid({  
				title:'书籍列表',  
				iconCls:'icon-save',   
				url:'/manager/book/findAll',
				columns:[
				    [
					{field:'bookname',title:'名称',width:100,align:'center'},
					{field:'author',title:'作者',width:200,align:'center'},
					{field:'price',title:'单价',width:80,align:'center'},
					{field:'iSBN',title:'ISBN',width:200,align:'center'},
					{field:'press',title:'出版社',width:200,align:'center',
                    formatter:function (value,row,index) {


                        return row.press.name;



                    }
                    },
	                {field:'supplier',title:'供货商',width:500,align:'center',
                        formatter:function (value,row,index) {


                            return row.supplier.name;



	                }
                    },
                    {field:'flag',title:'状态',width:100,align:'center',formatter:function(val,row) {
                            //val 当前field属性中的值
                            //row 当前行的党项信息
                            if (val == 0) {
                                return "禁用";
                            }
                            if (val == 1) {
                                return "启用";
                            }

                            return '数据丢失';
                        }
                    }
				]
                ],
				toolbar: toolbar,  
				pagination: true,//表示在datagrid设置分页              
               	pageSize: 5,
				singleSelect:true,
                pageList: [5,10,20]
			});

		 //初始化查询栏
		 $("#submit_search").linkbutton({ iconCls: 'icon-search', plain: true })
            .click(function () {
                $('#dg').datagrid({ queryParams: form2Json("searchform") });   //点击搜索
            });
          
          //初始化修改窗口  
         $('#dd').dialog({
			    title: 'My Dialog',
			    width: 700,
			    height: 500,
			    closed: true,
			    cache: false,
			    href: '',
			    modal: true,
			    iconCls: 'icon-save',
                buttons: [{
                    text:'提交',
                    iconCls:'icon-ok',
                    handler:function(){
                        var row=$('#booklist').datagrid('getSelected');
                        $('#bookId').val(row.id);
                        $('#ff').submit();

                    }
                },{
                    text:'关闭',
                    handler:function(){
                        $('#dd').dialog("close");
                    }
                }]
			});
            

	   });


	</script>
</head>
<body>
   <form name="searchform" method="post" action="" id ="searchform">
    <td width="70" height="30"><strong>书籍查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" size=20 placeholder="书籍名称"/>
        <input type="text" name="keyword" size=20 placeholder="ISBN"/>
        <select name="search_type" id="search_type" >
            <option value="-1">请选择出版社</option>
            <option value="be_name" >出版社1</option>
            <option value="be_intro">出版社2</option>
            <option value="be_intro">出版社3</option>
        </select>
        <select name="search_type" id="search_type" >
            <option value="-1">请选择供应商</option>
            <option value="be_name" >供应商1</option>
            <option value="be_intro">供应商2</option>
            <option value="be_intro">供应商3</option>
        </select>
        编辑推荐:<input type="checkbox" name="" value=""/>
        本周精选:<input type="checkbox" name="" value=""/>
    </td>
	<td>
	  <a id="submit_search">搜索</a>
	</td>
  </form>
  <table id="booklist"></table>
    <div id="dd">
           <div align="center" style="margin-top: 30px">
            <form id="ff" method="post" th:action="@{/manager/book/modifybook}" enctype=multipart/form-data>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="bookname" id="bookname" style="width:50%" data-options="label:'书籍名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="price" id="price" style="width:50%" data-options="label:'单价:',required:true,validType:'email'">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="groupprice" id="groupprice" style="width:50%" data-options="label:'团购价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="bookintroduce" id="bookintroduce" style="width:50%;height:60px" data-options="label:'书籍简介:',multiline:true">
            </div>
             <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="authorintroduce" id="authorintroduce" style="width:50%;height:60px" data-options="label:'作者简介:',multiline:true">
            </div>
             <div style="margin-bottom:20px">
               封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input  type="file" name="file" id="file"/>
            </div>
            <div style="margin-bottom:20px">
               编辑推荐:<input type="checkbox" name="" value=""/>
               本周精选:<input type="checkbox" name="" value=""/>
            </div>
            <input id="bookId" name="id" type="hidden">
        </form>
           </div>
    </div>
</body>
</html>